package birdsong.dummy;

import java.security.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import birdsong.comm.ServerComm;
import birdsong.comm.ServerSideMessage;
import birdsong.comm.ServerSideMessage.Type;

public class ServerCommDummy implements ServerComm {
	
	ArrayList<ServerSideMessage> listaMensagem = new ArrayList<ServerSideMessage>();
	int j = 0;
	@Override
	public void start() {
		
		//2
		for(int i=1; i<= 3; i++){
			ServerSideMessage as = new ServerSideMessage() {
				public Type getType() {
					return Type.BIRDSONG_MESSAGE;
				}

				public String getPayload() {
					return "message equals";
				}

				public String getClientNickname() {
					return "nobita";
				}
			};

			listaMensagem.add(as);
		}
		
		//3
		for(int i=1; i<= 10; i++){
			ServerSideMessage as = new ServerSideMessage() {
				public Type getType() {
					return Type.BIRDSONG_MESSAGE;
				}

				public String getPayload() {
					Calendar cal = Calendar.getInstance();
					return (cal.getTimeInMillis()* Math.random())+"";
				}

				public String getClientNickname() {
					return "nobita";
				}
			};

			listaMensagem.add(as);
		}
		
		//4
		for(int i=1; i<= 2; i++){
			ServerSideMessage as = new ServerSideMessage() {
				public Type getType() {
					return Type.BIRDSONG_MESSAGE;
				}

				public String getPayload() {
					return "ola";
				}

				public String getClientNickname() {
					return "nobita";
				}
			};

			listaMensagem.add(as);
		}
		
		//
		for(int i=1; i<=5; i++){
			ServerSideMessage as = new ServerSideMessage() {
				public Type getType() {
					return Type.BIRDSONG_MESSAGE;
				}

				public String getPayload() {
					Calendar cal = Calendar.getInstance();
					return (cal.getTimeInMillis()* Math.random())+"";
				}

				public String getClientNickname() {
					return "nobita"+j++;
				}
			};

			listaMensagem.add(as);
		}
	}

	@Override
	public boolean hasNextMessage() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public ServerSideMessage getNextMessage() {
		if(listaMensagem.size() > 0){
			ServerSideMessage mensagem  = listaMensagem.get(0);
			listaMensagem.remove(0);
			return mensagem;
		}
		
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void sendNewFollower(String toNickname, String newFollower) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void sendError(String toNickname, String error) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean clientIsConnected(String nickname) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void sendClientConnected(String toNickname, String userConnected) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void sendClientDisconnected(String toNickname, String userDisconnected) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void disconnectClient(String nickname) {
		//do we have to implement this method?
	}

	@Override
	public void sendBirdsongMessage(String fromNicename, String toNickname,
			String message) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void sendNewUnfollow(String toNickname, String newFollower) {
		// TODO Auto-generated method stub
		
	}
}
